package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageRequestDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.dtos.WmNewsDto;
import com.heima.model.common.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Lijx
 * @Date 2024-07-21 19:41
 */
@RestController
@RequestMapping("api/v1/news")
@Slf4j
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 分页查询文章列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult getPageList(@RequestBody WmNewsPageReqDto dto){
        log.info("分页查询文章列表接口，入参={}",dto);
        return wmNewsService.getPageList(dto);
    }

    /**
     * 文章发布
     * @param newsDto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto newsDto){
        log.info("文章发布接口，入参={}",newsDto);
        return wmNewsService.submitNews(newsDto);
    }

    /**
     * 查询文章详情
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult selectNewsDetail(@PathVariable Integer id){
        log.info("查询文章详情接口，入参id={}",id);
        return wmNewsService.selectNewsDetail(id);
    }

    /**
     * 删除文章
     * @param id
     * @return
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult deleteNewsById(@PathVariable Integer id){
        log.info("删除文章接口，入参id={}",id);
        return wmNewsService.deleteNewsById(id);
    }

    /**
     * 修改文章上下架
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto newsDto){
        log.info("修改文章上下架接口,本次操作：{}",newsDto.getEnable()==1?"上架":"下架");
        return wmNewsService.downOrUp(newsDto);
    }

}
